package com.sky.mapper;

import com.sky.annotation.AutoFill;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.entity.Category;
import com.sky.enumeration.OperationType;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface CategoryMapper {
    /**
     * 根据id删除对应分类
     * @param id 分类的id
     * @return 受影响行数
     */
    @Delete("delete from category where id=#{id}")
    int deleteById(Long id);

    /**
     * 类别分页查询的mapper层代码，作用是根据DTO要求查找所有符合条件的Category
     * @param categoryPageQueryDTO
     * @return
     */
    List<Category> page(CategoryPageQueryDTO categoryPageQueryDTO);

    /**
     * 插入新的类别
     * @param category
     * @return
     */
    @Insert("insert into category(type, name, sort, status, create_time, update_time, create_user, update_user) values(#{type},#{name},#{sort},#{status},#{createTime},#{updateTime},#{createUser},#{updateUser})")
    @AutoFill(OperationType.INSERT)
    int insertCategory(Category category);

    /**
     * 修改分类
     * @param category
     * @return
     */
    @AutoFill(OperationType.UPDATE)
    int updateCategory(Category category);
}
